package web.user; /**
 * 文件描述
 *
 * @author 冯根源
 * @date 2020/3/19 1:18
 */

import cn.itcast.vcode.utils.VerifyCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 *文件描述
 *
 *@author 冯根源
 *@date 2020/3/19 1:18
 */
@WebServlet(name = "VerifyCodeServlet", urlPatterns = "/VerifyCodeServlet")
public class VerifyCodeServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //创建验证码
        VerifyCode verifyCode = new VerifyCode();
        //得到图片验证码
        BufferedImage bufferedImage = verifyCode.getImage();
        //吧图片的文本保存到session中农
        request.getSession().setAttribute("session_verifyCode",verifyCode.getText());
        //把图片相应给客户端
        VerifyCode.output(bufferedImage,response.getOutputStream());

    }
}
